package io.github.maojian.str;

import org.junit.Test;

import java.util.HashSet;
import java.util.Set;


/**
 * @Auther: jian.mao
 * @Date: 2022/4/12 10:32
 * @Description: https://leetcode-cn.com/problems/unique-morse-code-words/
 */
public class Q804 {
    private static final String[] MORSE_CODE = new String[]{
            ".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."
    };
    public int uniqueMorseRepresentations(String[] words) {
        Set<String> translateSet = new HashSet<>();
        for(int i = 0;i < words.length;i++){
            String curWord = words[i];
            StringBuilder curTranslate = new StringBuilder();
            for(int j = 0;j < curWord.length();j++){
                curTranslate.append(MORSE_CODE[curWord.charAt(j)-'a']);
            }
            translateSet.add(String.valueOf(curTranslate));
        }
        return translateSet.size();
    }

    @Test
    public void test(){
        String[] worlds = new String[]{"gin", "zen", "gig", "msg"};
        System.out.println(uniqueMorseRepresentations(worlds));
    }
}
